package com.sk.bilibili.model.fragment.main.home.dynamic;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.mapper.DynamicMapper;
import com.sk.bilibili.mapper.FollowThemMapper;
import com.sk.bilibili.mapper.PraiseMapper;
import com.sk.bilibili.model.BaseRefreshModel;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.main.home.dynamic.VideoFragment;

public class VideoModel extends BaseRefreshModel<VideoFragment> {

    @Autowired
    FollowThemMapper followThemMapper;
    @Autowired
    DynamicMapper dynamicMapper;
    @Autowired
    PraiseMapper praiseMapper;
    private int size=10;
    private int page=1;

    @Override
    public void refreshData() {
        JsonMap map=new JsonMap();
        map.put("size",size);
        RequestUtils.process(followThemMapper.getFollowThem(map), followThemPage ->
                view.loadFollowThemSuccess(followThemPage.getRecords()));
        page=1;
        JsonMap jsonMap = getJsonMap();
        RequestUtils.process(dynamicMapper.getDynamic(jsonMap), dynamicPage ->{
            page++;
            view.refreshSuccess(dynamicPage.getRecords());
        });
    }

    private JsonMap getJsonMap() {
        JsonMap jsonMap=new JsonMap();
        jsonMap.put("size",size);
        jsonMap.put("page",page);
        jsonMap.put("type",0);
        return jsonMap;
    }

    @Override
    public void loadData() {
        JsonMap jsonMap = getJsonMap();
        RequestUtils.process(dynamicMapper.getDynamic(jsonMap), dynamicPage ->{
            page++;
            view.loadSuccess(dynamicPage.getRecords());
        });
    }

    public void praiseVideoSet(Integer id) {
        JsonMap map = new JsonMap();
        map.put("type",0);
        map.put("targetId",id);
        RequestUtils.process(praiseMapper.switchPraise(map),
                aBoolean -> view.praiseVideoSetSuccess());
    }

}